import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:webview_flutter/webview_flutter.dart';

class HorizontalBarCharts extends StatefulWidget {
  @override
  _HorizontalBarChartsState createState() => _HorizontalBarChartsState();
}

class _HorizontalBarChartsState extends State<HorizontalBarCharts> {
  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: fetchHtmlString(),
        builder: (context,snapshot){
          if (!snapshot.hasData) {
            return Center(
              child: SpinKitCircle(color: Colors.lightBlue,),
            );
          }
          String str = Uri.dataFromString(snapshot.data, mimeType: 'text/html', encoding: Encoding.getByName('utf-8')).toString();
          return WebView(
            javascriptMode: JavascriptMode.unrestricted,
            onWebViewCreated: (WebViewController controller) {
              controller.loadUrl(str);
            },
          );
      },
    );
  }

    Future fetchHtmlString() async {
    String filePath = 'lib/common/views/charts/horizontalBarChart.html';
    String fileHtmlContents = await rootBundle.loadString(filePath);
    return  fileHtmlContents;
  }
}